package com.fly.show.notepad.action;
//SaveAsAction.java

import org.eclipse.jface.action.Action;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.FileDialog;

import com.fly.show.notepad.FileManager;
import com.fly.show.notepad.MainWindow;

public class SaveAsAction extends Action
{
    public SaveAsAction()
    {
        super();
        setText("另存为(&A)");
        setToolTipText("另存为");
        setImageDescriptor(ImageDescriptor.createFromFile(NewAction.class, "icons\\saveas.gif"));
    }
    
    @Override
    public void run()
    {
        final FileManager fileManager = MainWindow.getApp().getManager();
        FileDialog saveDialog = new FileDialog(MainWindow.getApp().getShell(), SWT.SAVE);
        saveDialog.setText("请选择所要保存的文件");
        saveDialog.setFilterPath("F:\\");
        saveDialog.setFilterExtensions(new String[] {"*.java", "*.*"});
        String saveFile = saveDialog.open();
        if (saveFile != null)
        {
            fileManager.setFileName(saveFile);
            fileManager.setContent(MainWindow.getApp().getContent().getText());
            fileManager.save(fileManager.getFileName());
        }
        fileManager.setDirty(false);
        return;
    }
}